<html>
<style>
body {
  min-width:400px;
  overflow-x:hidden;
  font-family: Verdana;
  font-size: 10px;
  margin: 10px;
}
#affichage{
	text-align:center; 
}
#affichageNA{
	text-align:center; 
	border: 2px solid red;
}
table {
 text-align:center; 
 margin-left:auto; 
 margin-right:auto;
 border-collapse:collapse;
 width:90%;
 }
th, td {
 border:1px solid black;
 width:10%;
 }
th{
 color: #FFF;
 background-color: #666;
 }
td {
 text-align:center;
 }
</style>
<link type="text/css" href="css/eggplant/jquery-ui-1.8rc3.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8rc3.custom.min.js"></script>
<script type="text/javascript">
$(function(){
	$('#tabs').tabs();
});

var diapason = 0;
var longVib = 0;
var j = 0;
var nbreFrets = 0;
var t = 0;
	
	if(!localStorage.decimalPrecision){
		localStorage.decimalPrecision = 1000;
	}
	
function foo(){
	init();
	document.getElementById("affichage").innerHTML += "<table><tr>";
	document.getElementById("affichage").innerHTML += "<th>Fret</th>";
	document.getElementById("affichage").innerHTML += "<th>form nut</th>";
	document.getElementById("affichage").innerHTML += "<th>fret to fret</th></tr>";
	for(i=1;i<=nbreFrets;i++){
		longVib = calcul(longVib);
		document.getElementById("affichage").innerHTML += "<tr>";
		document.getElementById("affichage").innerHTML += "<td>" + i + "</td>";
		document.getElementById("affichage").innerHTML += "<td>" + arrondir((diapason - longVib)) + "</td>";
		document.getElementById("affichage").innerHTML += "<td>" + arrondir(((diapason - longVib) - j)) + "</td>";
		document.getElementById("affichage").innerHTML += "</tr>";
		j = (diapason - longVib);
	}
	document.getElementById("affichage").innerHTML += "</table>";
}

function format(){
	formata = document.getElementById("preformat");
	document.getElementById("diapas").value = formata.options[formata.selectedIndex].value;
}

function init(){
	document.getElementById("affichage").innerHTML = "";
	diapason = document.getElementById("diapas").value;
	longVib = document.getElementById("diapas").value;
	nbreFrets = document.getElementById("nbreFret").value;
	j = 0;
}

function calcul(res){
	res = res / Math.pow(2, 1/12);
	return res;
}
function arrondir(resultat) {
      resultat = Math.round(resultat*localStorage.decimalPrecision)/localStorage.decimalPrecision;
      return resultat;
}

function fooNA(){
	var cordierM = parseInt(document.getElementById("cordier_max").value);
	var cordierm = parseInt(document.getElementById("cordier_min").value);
	var nbrFret = parseInt(document.getElementById("nbreFretNA").value);
	var finger = parseInt(document.getElementById("fingerNA").value);
	var SL = parseInt(document.getElementById("diapasNA").value);
	
	t = SL;
	for(i=1;i<=nbrFret;i++){
		t = calcul(t);
	}
	
	var a = ((cordierM + cordierm) / 2) - (finger + 2); // fingerboard height + action height - average tailpiece height
	var b = t; // lenght between tail piece and point above last fret
	var result = arrondir((Math.asin(a/b)) * 180 / Math.PI);
	document.getElementById("affichageNA").innerHTML = "<strong>" + result + " (deg)</strong>";
}
</script>
<body>
<div id="tabs">
<ul>
	<li><a href="#tabs-1">Fret Calculator</a></li>
	<li><a href="#tabs-2">Neck Angle</a></li>
</ul>
	<div id="tabs-1">
		Guitar type : 
		<select onchange="format()" id="preformat">
			<option value="635">PRS</option>
			<option value="629">Gibson</option>
			<option value="648">Fender</option>
		</select>&nbsp;
		Scale length (mm) : 
		<input id="diapas" name="diapas" value="635"></input><br/>
		Number of frets : 
		<select id="nbreFret">
			<option value="22" selected>22 frets</option>
			<option value="24">24 frets</option>
		</select>
		<br/>
		<button onclick="foo()">Calculate</button><br/>(mm = millimeters)<br/><br/>		
		<div id="affichage"></div>		
	</div>
	<div id="tabs-2">
	Maximum tailpiece height (mm) :
	<input id="cordier_max" name="cordier_max" value="17"></input><br/>
	Minimum tailpiece height (mm) :&nbsp;
	<input id="cordier_min" name="cordier_min" value="13"></input><br/>
	Scale length (mm) : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input id="diapasNA" name="diapasNA" value="635"></input><br/>
	Fingerboard height (mm) :&nbsp;
	<input id="fingerNA" name="fingerNA" value="5"></input><br/>
	Number of frets : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<select id="nbreFretNA">
			<option value="22" selected>22 frets</option>
			<option value="24">24 frets</option>
		</select><br/>
	<button onclick="fooNA()">Calculate</button><br/>(mm = millimeters)<br/><br/>		
	<div id="affichageNA"></div>	
	</div>
</div>
</body>
</html>